package cn.edu.cug.cs.gtl.docsrv.dict.controller;

import cn.edu.cug.cs.gtl.docsrv.dict.exception.BaseException;
import cn.edu.cug.cs.gtl.docsrv.dict.service.DictCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/dict/catalog")
public class DictCatalogController {

    @Autowired
    DictCatalogService dictCatalogService;
    //获取主数据源的所有表分类结果
    @GetMapping(value = "/getMasterCatalogs")
    public Object getMasterCatalogs() {
        try {
            return dictCatalogService.getMasterCatalogs();
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
    }

    //获取指定从属数据源的所有表分类结果
    @GetMapping(value = "/getSlaveCatalogs")
    public Object getSlaveCatalogs(@RequestParam(value = "slaveDataSourceName") String slaveDataSourceName) {
        try {
            return dictCatalogService.getSlaveCatalogs(slaveDataSourceName);
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
    }

    //获取主数据源的所有表分类结果
    @Deprecated
    @GetMapping(value = "/getMasterCatalogsV1")
    public Object getMasterCatalogsV1() {
        try {
            return dictCatalogService.getMasterCatalogsV1();
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
    }

    //获取指定从属数据源的所有表分类结果
    @GetMapping(value = "/getSlaveCatalogsV1")
    public Object getSlaveCatalogsV1(@RequestParam(value = "slaveDataSourceName") String slaveDataSourceName) {
        try {
            return dictCatalogService.getSlaveCatalogsV1(slaveDataSourceName);
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
    }
}
